/**
 * 過濾特殊符號為空白
 * @returns
 */
String.prototype.filter = function(){		
	//var regEx = /\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g;		
	var regEx = /\<|\>|\"|\'|\&|\=|\?/g;
	return this.replace(regEx,"");	
};	

/**
 * 將特殊符號轉Entity Name
 * @returns
 */
String.prototype.escapeHTML = function(){	
	return this.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
};	

/**
 * 將Entity Name轉為符號
 * @returns
 */
String.prototype.unescapeHTML = function(){	
	return this.replace(/&amp;/g, '&').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&quot;/g, '"').replace(/&#39;/g, '\'');
};

/**
 * 回傳byte數
 * @returns
 */
String.prototype.Blength = function() {
	var arr = this.match(/[^\x00-\xff]/ig);
	return  arr == null ? this.length : this.length + arr.length;
};

/**
 * 1. 移除逗號和數字以外的字元符號
 * 2. 判別除了0-9以為的符號轉為逗號
 * 3. 判斷電話號碼長度為9, 開頭為9則自動補0
 * @returns
 */
String.prototype.removeExtraString = function ()
{
    var txt = this.toString();
    //將除了0-9以外的字或符號轉為逗號
    txt = txt.replace(/[^0-9,]/g, ",");
    var txts = txt.split(",");
    var str = [];
    $.each(txts, function(i, elem){
    	if($.trim(elem)!="" && $.trim(elem).replace(/[^0-9,]/g,"")!=""){
    		var mobileNo = $.trim(elem).replace(/[^0-9,]/g,"");
    		//判斷電話號碼長度為9, 開頭為9則自動補0
    		if(mobileNo.length == 9 && mobileNo.charAt(0) == '9'){
    			mobileNo = '0' + mobileNo;
    		}    		
    		str.push(mobileNo);
    	}
    });
    
    return str.join(",");
};
